<#assign base=request.contextPath />
<!DOCTYPE html>
<div class="row">
	<div class="col-md-12 col-sm-12 col-xs-12">
		<div class="x_panel">
			<div class="x_title">
				<h2>景点编辑<small></small></h2>
				<div class="clearfix"></div>
			</div>
			<div class="x_content">
				<br/>
				<form id="postForm" data-parsley-validate class="form-horizontal form-label-left" method="post" action="${base}/gx/sysScenic/save">
					<input type="hidden" id="id" name="id" value="${((obj.id)?c)!0 }">
		            <input type="hidden" name="addTime" value="${(obj.addTime)!.now?string['yyyy-MM-dd HH:mm:ss']}">
		          
		            <input type="hidden" name="addName" value="${(obj.addName)!admin.userName}">
		           
		            <input type="hidden" name="isDelete" value="${((obj.isDelete)?c)!0 }">
		           
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">景点名称 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="scenicName" name="scenicName" value="${(obj.scenicName)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">英文名称 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="englishName" name="englishName" value="${(obj.englishName)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">景点类型 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<select id="scenicType" name="scenicType" class="form-control select2">
                        		<option value="">请选择</option>
	         					<option value="1">教育</option>
		                        <option value="2">休息餐饮</option>
		                        <option value="3">游玩娱乐</option>
		                
	                    	</select>
                        </div>
					</div>
					
			
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">景点图片 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="file" id="icon_dropify" name="file" class="dropify" data-default-file="${imagePath}${(obj.scenicImg)!''}" />
                            <input type="hidden" name="scenicImg" id="scenicImg" value="${(obj.scenicImg)!''}">
                            <input type="hidden" name="scenicImgOld" id="scenicImgOld" value="${(obj.scenicImg)!''}">
                        </div>
					</div>

					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">景点地址 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="scenicAddress" name="scenicAddress" value="${(obj.scenicAddress)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">景点介绍 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<div id="content_summernote" class="summernote" >
                                        ${(obj.scenicContent)!''}
                        	</div>
                            <input type="hidden" name="scenicContent" id="scenicContent">
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">收费标准 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="chargeType" name="chargeType" value="${(obj.chargeType)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
	

					<div class="ln_solid"></div>
					<div class="form-group">
						<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
							<button type="button" class="btn btn-success" id="submit">保存</button>
							<button type="button" class="btn btn-primary" id="goBack">返回</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
$(function() {
	//select2
	$(".select2").select2({width: "100%"});
	$('.summernote').summernote({
        height: 350, // set editor height
        minHeight: null, // set minimum height of editor
        maxHeight: null, // set maximum height of editor
        focus: false, // set focus to editable area after initializing summernote
        lang: 'zh-CN',
        shortcuts:false //禁止使用快捷键
    });
	 $('.dropify').dropify({
     	messages: {
		        'default': '点击或拖拽文件到这里',
		        'replace': '点击或拖拽文件到这里来替换文件',
		        'remove':  '移除文件',
		        'error':   '对不起，你上传的文件太大了',
		    }
     });
     // Used events
     drEvent = $('#icon_dropify').dropify();
     drEvent.on('dropify.afterClear', function(event, element) {
     	$("#infoIcon").val("");
     });

     drEvent.on('dropify.errors', function(event, element) {
         console.log('Has Errors');
     });

	$("#goBack").click(function() {
		$("#main_content").load('${base}/gx/sysScenic/list');	        
    });
	
	$("#submit").click(function() {
	
		var scenicName = $.trim($("#scenicName").val());
		var scenicAddress = $.trim($("#scenicAddress").val());
		var chargeType = $.trim($("#chargeType").val());
		
    	if(scenicName==""){
    		swal("请输入景点标题");
            return;
    	}
    	
    	if(englishName==""){
    		swal("请输入景点英文名");
            return;
    	}

    	//获取数据
		drEvent = $('.dropify').dropify();
	    drEvent=drEvent.data('dropify')
	    if((drEvent.file.object !=null )){
	    	var scenicImg = drEvent.callBackBase64;
	    	scenicImg = scenicImg.substring(scenicImg.indexOf("base64")+7);
	    	$("#scenicImg").val(scenicImg);
	    }else{
	    	if($("#scenicImg").val()==""){
	    		swal("请上传资讯封面图");
	            return;
	    	}
	    }

    	var markupStr = $('#content_summernote').summernote('code');
    	markupStr=filterhtml(markupStr);
		$("#scenicContent").val(markupStr);
		var scenicContent = $.trim($("#scenicContent").val());
    	if(scenicContent==""){
    		swal("请输入景点介绍");
            return;
    	}


        $("#postForm").ajaxSubmit(function(data) {
    	 	if (data.flag) {
    	 		swal(data.msg, "", "success");
				$("#main_content").load('${base}/gx/sysScenic/list');
    	 	} 
    	 	else {
    	 		swal(data.msg, "", "error");
    	 	}
    	});
	});
});


function filterhtml(msg) {
        var msg = msg.replace(/<\/?[^>]*>/g, ''); //去除HTML Tag
        msg = msg.replace(/[|]*\n/, '') //去除行尾空格
        msg = msg.replace(/&nbsp;/ig, ''); //去掉npsp
        return msg;
        }
</script>